//
//  BaseTableViewController.swift
//  HMWeibo08
//
//  Created by 唐万超 on 15/7/28.
//  Copyright © 2015年 唐万超. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController, VisitorLoginViewDelegate {

    var visitorView: VisitorLoginView?
    
    // 判断用户是否登录
    var userLogon = UserAccount.userLogon
    
   // var userLogon = false
   // var userLogon = UserAccount.loadAccount() != nil
    
    override func loadView() {
        userLogon ? super.loadView() : setUpVisitorView()
    }
  
    // 登陆未成功的控制器
    private func setUpVisitorView() {
    
        visitorView = VisitorLoginView()
        
        // 设置代理
        visitorView?.delegate = self
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewWillRegister")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewWillLogin")
        
        view = visitorView
        
    }
    
    /// 执行代理方法
    func visitorViewWillLogin() {
        
        // 点击登录之后modal出OAuth控制器
        let nav = UINavigationController(rootViewController: OAuthViewController())
        
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
    func visitorViewWillRegister() {
       print("注册")
    }


}
